package com.cnswhy.cloud.server.core.service.customer.impl;


import com.cnswhy.cloud.common.core.base.service.SuperServiceImpl;
import com.cnswhy.cloud.common.core.mybatis.conditions.Wraps;
import com.cnswhy.cloud.server.app.utils.RSAUtils;
import com.cnswhy.cloud.server.core.dao.CustomerMapper;
import com.cnswhy.cloud.server.core.entity.Customer;
import com.cnswhy.cloud.server.core.service.customer.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 业务实现类
 * 
 * </p>
 *
 * @author cnswhy
 * @date 2020-09-29
 */
@Slf4j
@Service

public class CustomerServiceImpl extends SuperServiceImpl<CustomerMapper, Customer> implements CustomerService {
    @Override
    public Long getSum() {
        return baseMapper.getSum();
    }

    @Override
    public Long getSumToday() {
        return baseMapper.getSumToday();
    }

    @Override
    public Customer queryByLoginName(String loginName) {
        Customer customer = super.getOne(Wraps.<Customer>lbQ().eq(Customer::getLoginName, loginName));
        return customer;
    }

    @Override
    public Customer queryById(Long id) {
        return super.getById(id);
    }

    @Override
    public Boolean checkPasswd(String oldPasswd, String passwd) {

        try {
            oldPasswd = RSAUtils.decryptString(oldPasswd);//解密
            passwd = RSAUtils.decryptString(passwd);//解密


        } catch (Exception e) {
            log.info("<== RSA解密，异常", e);
        }
        return oldPasswd.equals(passwd);
    }

}
